package pers.lonestar.framework.utils.support.metadata;

import java.math.BigDecimal;

import org.apache.poi.ss.usermodel.CellStyle;

import pers.lonestar.framework.utils.support.enums.CellDataTypeEnum;
import pers.lonestar.framework.utils.support.utils.StringUtil;

public class CellData<T> extends AbstractCell {
    private CellDataTypeEnum type;
    private CellStyle cellStyle;
    private BigDecimal numberValue;
    private String stringValue;
    private Boolean booleanValue;
    private Integer dataFormat;
    private String dataFormatString;
    private T data;

    public CellData() {
    }

    public CellData(CellDataTypeEnum type) {
        this.type = type;
    }

    public boolean checkEmpty() {
        if (type == null) {
            type = CellDataTypeEnum.EMPTY;
        }
        switch (type) {
            case STRING:
            case ERROR:
                if (StringUtil.isEmpty(stringValue)) {
                    type = CellDataTypeEnum.EMPTY;
                }
                break;
            case NUMBER:
            case DATE:
                if (numberValue == null) {
                    type = CellDataTypeEnum.EMPTY;
                }
                break;
            case BOOLEAN:
                if (booleanValue == null) {
                    type = CellDataTypeEnum.EMPTY;
                }
                break;
            default:
        }
        return type == CellDataTypeEnum.EMPTY;
    }

    @Override
    public String toString() {
        if (type == null) {
            return StringUtil.EMPTY;
        }
        switch (type) {
            case NUMBER:
                return numberValue.toString();
            case BOOLEAN:
                return booleanValue.toString();
            case DIRECT_STRING:
            case STRING:
            case ERROR:
                return stringValue;
            default:
                return StringUtil.EMPTY;
        }
    }

    public Object getValue() {
        switch (type) {
            case STRING:
            case DIRECT_STRING:
            case EMPTY:
            case ERROR:
                return getStringValue();
            case NUMBER:
            case DATE:
                return getNumberValue();
            case BOOLEAN:
                return getBooleanValue();
            default:
                return null;
        }
    }

    public CellDataTypeEnum getType() {
        return this.type;
    }

    public void setType(CellDataTypeEnum type) {
        this.type = type;
    }

    public CellStyle getCellStyle() {
        return this.cellStyle;
    }

    public void setCellStyle(CellStyle cellStyle) {
        this.cellStyle = cellStyle;
    }

    public BigDecimal getNumberValue() {
        return this.numberValue;
    }

    public void setNumberValue(BigDecimal numberValue) {
        this.numberValue = numberValue;
    }

    public String getStringValue() {
        return this.stringValue;
    }

    public void setStringValue(String stringValue) {
        this.stringValue = stringValue;
    }

    public Boolean getBooleanValue() {
        return this.booleanValue;
    }

    public void setBooleanValue(Boolean booleanValue) {
        this.booleanValue = booleanValue;
    }

    public Integer getDataFormat() {
        return this.dataFormat;
    }

    public void setDataFormat(Integer dataFormat) {
        this.dataFormat = dataFormat;
    }

    public String getDataFormatString() {
        return this.dataFormatString;
    }

    public void setDataFormatString(String dataFormatString) {
        this.dataFormatString = dataFormatString;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
